import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_base/dk_ui.dart';

class TipDialogWidget extends StatelessWidget {
  final TipDialogOption tipDialogOption;

  TipDialogWidget(this.tipDialogOption);

  @override
  Widget build(BuildContext context) {
    List<Widget> list = List();
    Divider divider = Divider(height: 0.5, color: Color(0xffDBDBDB));
    if (null != tipDialogOption.titleOption) {
      list.add(DkText.withOption(tipDialogOption.titleOption));
      list.add(divider);
    }

    list.add(Padding(
        padding: EdgeInsets.all(38.0),
        child: DkText.withOption(tipDialogOption.contentOption)));
    list.add(divider);

    list.add(Row(
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Expanded(
          flex: 1,
          child: MaterialButton(
              height: 45,
              child: DkText.withOption(tipDialogOption.cancelOption),
              onPressed: () {
                Navigator.of(context).pop(false);
              }),
        ),
        SizedBox(
          height: 45,
          child: VerticalDivider(
            width: 0.5,
            color: Color(0xffDBDBDB),
          ),
        ),
        Expanded(
          flex: 1,
          child: MaterialButton(
              height: 45,
              child: DkText.withOption(tipDialogOption.confirmOption),
              onPressed: () {
                Navigator.of(context).pop(true);
              }),
        ),
      ],
    ));
    return Container(
      margin: EdgeInsets.all(39),
      child: Material(
        color: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(15.0),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: list,
        ),
      ),
    );
  }
}

enum TipDialogType {
  normal,
}

class TipDialogOption {
  TipDialogType tipDialogType;
  TextOption titleOption;
  TextOption contentOption;
  TextOption cancelOption;
  TextOption confirmOption;

  TipDialogOption.normalWithContent(
    String content, {
    String title,
    String cancel,
    String confirm,
  }) {
    if (stringNotEmpty(title)) {
      titleOption = TextOption.simple(title, 18, Color(0xff333333));
    }
    contentOption = TextOption.simple(content, 18, Color(0xff333333));
    cancelOption = TextOption.simple(
        stringNotEmpty(cancel) ? cancel : "取消", 18, Color(0xFF3DBCC6));
    confirmOption = TextOption.simple(
        stringNotEmpty(confirm) ? cancel : "确定", 18, Color(0xFF3DBCC6));
    this.tipDialogType = TipDialogType.normal;
  }

  TipDialogOption.normalWithOption(
    this.contentOption, {
    this.titleOption,
    this.cancelOption,
    this.confirmOption,
  }) {
    this.tipDialogType = TipDialogType.normal;
    cancelOption ??= TextOption.simple("取消", 18, Color(0xFF3DBCC6));
    confirmOption ??= TextOption.simple("确定", 18, Color(0xFF3DBCC6));
  }
}
